<template>
  <div class="goodslist">
    <header class="goods_header">商品列表</header>
    <div class="goods_body">
      <van-row>
        <van-list
          v-model="loading"
          :finished="finished"
          finished-text="没有更多了"
          @load="onLoad"
          :immediate-check="false"
          :offset="5"
        >
          <van-col
            span="12"
            class="goods_item"
            v-for="item in goodsList"
            :key="item.id"
            @click="$router.push({ path: '/goods/info/' + item.id })"
          >
            <img :src="item.img_url" alt="" />
            <div class="goods_info">
              <p>{{ item.title }}</p>
              <div class="price">
                <span style="color: red">¥{{ item.sell_price }}</span>
                <span class="oldprice">¥{{ item.market_price }}</span>
              </div>
              <div class="tips">
                <span>热卖中</span>
                <span>剩{{ item.stock_quantity }}件</span>
              </div>
            </div>
          </van-col>
        </van-list>
      </van-row>
    </div>
    <!-- <footer class="footer"></footer> -->
  </div>
</template>

<script>
import { getGoodsList } from "@/api/goods.js";
export default {
  data() {
    return {
      goodsList: [],
      loading: false,
      finished: false,
      pageindex: 1,
    };
  },
  mounted() {
    this.init();
  },
  methods: {
    async init() {
      let res = await getGoodsList({ pageindex: this.pageindex });
      console.log(res);
      this.goodsList.push(...res.data.message);
      this.loading = false;
      if (res.data.message.length === 0) {
        this.finished = true;
      }
    },
    onLoad() {
      this.pageindex++;
      this.init();
    },
  },
};
</script>

<style lang="less" scoped>
.goodslist {
  box-sizing: border-box;
  padding-top: 40px;
  padding-bottom: 50px;
}
.goods_header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 40px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 18px;
  color: #fff;
  background-color: #26a2ff;
}
.goods_body {
  margin-top: 5px;
  // padding: 0 5px;
  // background-color: pink;
  /deep/.van-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    padding: 0 5px;
  }
  .goods_item {
    width: 49%;
    font-size: 17px;
    // padding: 10px 0 0 14px;
    // padding: 5px;
    text-align: center;
    vertical-align: middle;
    margin-bottom: 6px;
    margin-right: 3px;
    padding: 3px;
    border: 1px solid #ccc;
    // box-shadow: 0 0 4px #666;
    > img {
      width: 100%;
      height: auto;
    }
    .goods_info {
      width: 100%;
      height: 110px;
      display: flex;
      flex-direction: column;
      font-size: 15px;
      line-height: 15px;
      // margin-top: 8px;
      text-overflow: ellipsis;
      color: #333;
      p {
        color: #000;
        font-size: 12px;
        text-align: left;
        overflow: hidden;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
      }
      .price {
        text-align: left;
        padding: 8px 5px;
        border-bottom: 1px solid #f0f0f0;
        border-top: 1px solid #f0f0f0;
        background: #f0f0f0;
        .oldprice {
          color: #5c5c5c;
          font-size: 12px;
          margin-left: 10px;
          text-decoration: line-through;
        }
      }
      .tips {
        flex: 1;
        display: flex;
        padding: 0 5px;
        justify-content: space-between;
        font-size: 12px;
        background: #f0f0f0;
      }
    }
  }
}
</style>